package com.itheima.demo;

import com.itheima.domain.Dept;
import com.itheima.domain.Emp;
import com.itheima.mapper.DeptMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.utils.MapperUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class Demo {
    public static void main(String[] args) {
        EmpMapper mapper = MapperUtil.getMapper(EmpMapper.class);
        List<Emp> list = mapper.findAll();
        for (Emp emp : list) {
            System.out.println(emp.getEname());
            Dept dept = emp.getDept();
            System.out.println(dept.getDname());
            System.out.println("========");
        }
    }

    //逆向获取新增主键列
    @Test
    public void insert(){
        SqlSession session = MapperUtil.getSession();
        EmpMapper mapper = session.getMapper(EmpMapper.class);
        Emp emp = new Emp();
        emp.setEname("王五");
        emp.setJob("manager");
        emp.setSal(1000.0);
        System.out.println(emp.getEmpno());
        mapper.insert(emp);
        System.out.println(emp.getEmpno());
        MapperUtil.close(session);
    }

    @Test
    public void delete(){
        SqlSession session = MapperUtil.getSession();
        EmpMapper mapper = session.getMapper(EmpMapper.class);
        mapper.delete(7936);
        MapperUtil.close(session);
    }
}
